package com.xyc.gulimall.order.controller;

import com.xyc.gulimall.order.entity.OrderEntity;
import com.xyc.gulimall.order.entity.OrderReturnReasonEntity;
import jakarta.annotation.Resource;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.UUID;

@RestController
public class SendMessage {

    @Resource
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/sendMessage")
    public String sendMessage() {
        //1、发送消息
        for (int i = 0; i < 10; i++) {
            if (i % 2 == 0) {
                OrderReturnReasonEntity orderReturnReasonEntity = new OrderReturnReasonEntity();
                orderReturnReasonEntity.setId(1L);
                orderReturnReasonEntity.setCreateTime(new Date());
                orderReturnReasonEntity.setName("好爱好爱你-" + i);
                rabbitTemplate.convertAndSend(
                        "hello-java-exchange",
                        "hello.java",
                        orderReturnReasonEntity,
                        new CorrelationData(UUID.randomUUID().toString())
                );
            } else {
                OrderEntity orderEntity = new OrderEntity();
                orderEntity.setOrderSn(UUID.randomUUID().toString());
                rabbitTemplate.convertAndSend(
                        "hello-java-exchange",
                        "hello.java2222",
                        orderEntity,
                        new CorrelationData(UUID.randomUUID().toString())
                );
            }
        }
        return "ok";
    }
}
